package com.cowmooed.controller;


import com.cowmooed.entity.Result;
import com.cowmooed.service.impl.UploadService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/file")
@Api(tags = "文件上传")
public class FileController {

    @Autowired
    UploadService uploadService;

    @PostMapping("/upload")
    @ApiOperation(value = "上传文件" , notes = "上传文件接口")
    public Result upload(MultipartFile file) {
        System.out.println("上传文件时前端所传参数: " +file);
        String finalUrl = uploadService.upload(file);
        return Result.success(finalUrl);
    }
}
